package nc.gk.gkxm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import nc.gk.gkxm.mapper.OptionMapper;
import nc.gk.gkxm.model.entity.Option;
import nc.gk.gkxm.model.vo.OptionVO;
import nc.gk.gkxm.model.vo.TopicVO;
import nc.gk.gkxm.service.OptionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OptionServiceImpl extends ServiceImpl<OptionMapper, Option> implements OptionService {
    @Override
    public List<OptionVO> getOptionByTopicId(Integer topicId) throws Exception {
        QueryWrapper<Option> wrapper = new QueryWrapper<>();
        wrapper.eq("topicid",topicId);
        List<Option> options = baseMapper.selectList(wrapper);
//        if(options == null || options.size() < 1){
//            throw new Exception("选项没有任何数据,请联系管理员进行维护");
//        }
        List<OptionVO> vos = new ArrayList<>();
        for(Option option : options){
            OptionVO vo = new OptionVO();
            vo.setOption(option.getOptiont());
            vo.setTopicid(option.getTopicid());
            vo.setOptionno(option.getOptionno());
            vos.add(vo);
        }
        return vos;
    }

    @Override
    public void inputOption(Option option) {
        baseMapper.insert(option);
    }
}
